{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本代码用来给指定的根据指定的csv文件生成对应的特征列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 导入包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  \n",
    "import pandas as pd\n",
    "import math\n",
    "import os\n",
    "from scipy.fftpack import fft,ifft\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.axes as axes\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 加载文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>us</th>\n",
       "      <th>acc</th>\n",
       "      <th>ws</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15:52:08.395</td>\n",
       "      <td>1012464</td>\n",
       "      <td>0.03598</td>\n",
       "      <td>2.27844</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15:52:08.433</td>\n",
       "      <td>1044468</td>\n",
       "      <td>0.03342</td>\n",
       "      <td>2.23848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15:52:08.433</td>\n",
       "      <td>1076472</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>2.43992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15:52:08.471</td>\n",
       "      <td>1108476</td>\n",
       "      <td>0.03703</td>\n",
       "      <td>2.40637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15:52:08.508</td>\n",
       "      <td>1140476</td>\n",
       "      <td>0.03831</td>\n",
       "      <td>2.15383</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           time       us      acc       ws\n",
       "0  15:52:08.395  1012464  0.03598  2.27844\n",
       "1  15:52:08.433  1044468  0.03342  2.23848\n",
       "2  15:52:08.433  1076472  0.03821  2.43992\n",
       "3  15:52:08.471  1108476  0.03703  2.40637\n",
       "4  15:52:08.508  1140476  0.03831  2.15383"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "csv_filename = \"printer.csv\"\n",
    "df = pd.read_csv(csv_filename,names=[\"time\",\"us\",\"acc\",\"ws\"])\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. 处理文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>us</th>\n",
       "      <th>acc</th>\n",
       "      <th>ws</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15:52:08.395</td>\n",
       "      <td>1012464</td>\n",
       "      <td>35.98</td>\n",
       "      <td>2.27844</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15:52:08.433</td>\n",
       "      <td>1044468</td>\n",
       "      <td>33.42</td>\n",
       "      <td>2.23848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>15:52:08.433</td>\n",
       "      <td>1076472</td>\n",
       "      <td>38.21</td>\n",
       "      <td>2.43992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15:52:08.471</td>\n",
       "      <td>1108476</td>\n",
       "      <td>37.03</td>\n",
       "      <td>2.40637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>15:52:08.508</td>\n",
       "      <td>1140476</td>\n",
       "      <td>38.31</td>\n",
       "      <td>2.15383</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           time       us    acc       ws\n",
       "0  15:52:08.395  1012464  35.98  2.27844\n",
       "1  15:52:08.433  1044468  33.42  2.23848\n",
       "2  15:52:08.433  1076472  38.21  2.43992\n",
       "3  15:52:08.471  1108476  37.03  2.40637\n",
       "4  15:52:08.508  1140476  38.31  2.15383"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"acc\"] = df[\"acc\"]*1000\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 保存文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "## index=0,去掉索引列\n",
    "df.to_csv(csv_filename,float_format='%.2f',index=0,columns=['time',\"us\",\"acc\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
